

/**
 * 日志类
 * @class Log
 * @summary 日志输出, window下的全局变量
 * @author IGER
 * @example
 Log.d('Game', 'this is a degbug log .')
 Log.i('Game', 'this is a info log .')
 Log.w('Game', 'this is a warning log .')
 Log.e('Game', 'this is a error log .')
 //设置日志等级, 默认等级为0
 Log.setLevel(1)
 */

let cc_browser = cc.sys.isBrowser
let format     = cc.js.formatStr

let mLevel     = 0

module.exports = {

    d()
    {
        if (mLevel > 0)
        {
            return
        }
        console.log(format.apply(null, arguments))
    },

    i()
    {
        if (mLevel > 1)
        {
            return
        }
        
        cc_browser ? console.info('%c%s', 'color:#00CD00;', format.apply(null, arguments)) : console.info(format.apply(null, arguments))
    },

    w()
    {
        if (mLevel > 2)
        {
            return
        }

        cc_browser ? console.warn('%c%s', 'color:#EE7700;', format.apply(null, arguments)) : console.warn(format.apply(null, arguments))
    },

    e()
    {
        if (mLevel > 3)
        {
            return
        }
        console.error(format.apply(null, arguments))
    },

    /**
     * 设置日志等级
     *
     * @param {Number} lv - 默认等级为0
     */
    setLevel(lv)
    {
        mLevel = lv
    }
}
